package game;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;

public class Zombie extends GameObject {

	private ArrayList<Point> path = new ArrayList<Point>();
	private ArrayList<Point> walked = new ArrayList<Point>();

	double px, py;
	double vx, vy;
	double bloodie = 0;
	double health = 10;
	public Zombie(double x, double y, GameField field) {
		super(0, 0, field);
		px = x;
		py = y;
		this.x = (int) x;
		this.y = (int) y;
		move();
	}

	public void draw(Graphics g) {
		g.setColor(new Color(0,200,0));
		g.fillOval((int) px-3, (int) py-3, 6, 6);
	}

	public void run() {
		
		if (bloodie > 0)
			bloodie -= 0.1;
		else
			bloodie = 0;
		
		vx *= 0.9;
		vy *= 0.9;
		
		px += vx;
		if (field.readSmell((int) (px / field.bsize), (int) (py / field.bsize)) == 0) {
			px -= vx * 2;
			vx *= -0.1;
		}
		py += vy;
		if (field.readSmell((int) (px / field.bsize), (int) (py / field.bsize)) == 0) {
			py -= vy * 2;
			vy *= -0.1;
		}
		x = (int) px;
		y = (int) py;
		move();

	}

	public void collide(Zombie other) {
		if (Math.abs(other.px - px) < 10 && Math.abs(other.py - py) < 10) {
			vx -= (other.px - px) * 0.01;
			vy -= (other.py - py) * 0.01;
		}
	}

	public void move() {
		double speed = 0.02;

		vx += Math.random() * 0.1 - 0.05;
		vy += Math.random() * 0.1 - 0.05;

		if (field.readSmell((int) (px / field.bsize), (int) (py / field.bsize)) < 25)
			return;

		if (Math.random() > 0.49) {
			if (field.readSmell((int) (px / field.bsize) + 1,
					(int) (py / field.bsize)) > field.readSmell(
					(int) (px / field.bsize), (int) (py / field.bsize))) {
				vx += speed;
			} else if (field.readSmell((int) (px / field.bsize) - 1,
					(int) (py / field.bsize)) > field.readSmell(
					(int) (px / field.bsize), (int) (py / field.bsize))) {
				vx -= speed;
			}
		} else {
			if (field.readSmell((int) (px / field.bsize) - 1,
					(int) (py / field.bsize)) > field.readSmell(
					(int) (px / field.bsize), (int) (py / field.bsize))) {
				vx -= speed;
			} else if (field.readSmell((int) (px / field.bsize) + 1,
					(int) (py / field.bsize)) > field.readSmell(
					(int) (px / field.bsize), (int) (py / field.bsize))) {
				vx += speed;
			}
		}

		if (Math.random() > 0.49) {
			if (field.readSmell((int) (px / field.bsize),
					(int) (py / field.bsize) + 1) > field.readSmell(
					(int) (px / field.bsize), (int) (py / field.bsize))) {
				vy += speed;
			} else if (field.readSmell((int) (px / field.bsize),
					(int) (py / field.bsize) - 1) > field.readSmell(
					(int) (px / field.bsize), (int) (py / field.bsize))) {
				vy -= speed;
			}
		} else {
			if (field.readSmell((int) (px / field.bsize),
					(int) (py / field.bsize) - 1) > field.readSmell(
					(int) (px / field.bsize), (int) (py / field.bsize))) {
				vy -= speed;
			} else if (field.readSmell((int) (px / field.bsize),
					(int) (py / field.bsize) + 1) > field.readSmell(
					(int) (px / field.bsize), (int) (py / field.bsize))) {
				vy += speed;
			}
		}

		vx *= 0.9;
		vy *= 0.9;

	}

	public ArrayList<Point> recPath(ArrayList<Point> prevPoints) {

		return prevPoints;
	}

}
